package Java攻略._3_流式操作._3_利用reduce方法实现归约操作;

import java.util.Arrays;
import java.util.OptionalDouble;
import java.util.OptionalInt;

public class _14_IntStream接口的归约操作 {

    public static void main(String[] args) {

        String[] strings = "this is an array of strings".split(" ");

        long count = Arrays.stream(strings)
                .map(n -> n.length())
                .count();
        System.out.println(count);


        int sum = Arrays.stream(strings)
                .mapToInt(n -> n.length())
                .sum();
        System.out.println(sum);


        OptionalDouble average = Arrays.stream(strings)
                .mapToInt(String::length)
                .average();
        System.out.println(average);


        OptionalInt max = Arrays.stream(strings)
                .mapToInt(String::length)
                .max();
        System.out.println(max);


        OptionalInt min = Arrays.stream(strings)
                .mapToInt(String::length)
                .min();
        System.out.println(min);

    }
}
